package com.yaorange.medical.controller;

import com.yaorange.medical.service.BreathDataService;
import com.yaorange.medical.vo.ParsedBreathRealVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author coach tam
 * @email 327395128@qq.com
 * @values 坚持灵活 灵活坚持
 * @since 2024/6/7
 */
@Slf4j
@RestController
@RequestMapping("/breath")
public class BreathController {

    @Resource
    private BreathDataService breathDataService;

    /**
     * 接收医疗设备密文数据接口
     */
    @PostMapping(value = "/receive",produces = "application/json;charset=UTF-8")
    public ResponseEntity<String> receive(@RequestBody String breathData) {
        log.info("1.接收到客户端报文");
        long begin = System.currentTimeMillis();
        breathDataService.parseAndSaveBreathData(breathData);
        log.info("2.接口响应耗时: {}ms", System.currentTimeMillis() - begin);
        return ResponseEntity.ok("{\"code\":\"200\"}");
    }

    /**
     * 获取医疗设备数据接口
     */
    @GetMapping(value = "/view",produces = "application/json;charset=UTF-8")
    public ResponseEntity<?> getBreathRealCollectDataById(@RequestParam("id") String id) {
        ParsedBreathRealVo result = breathDataService.getParsedBreathRealDataByRealId(id);
        if (result == null) {
            return ResponseEntity.status(404).body("breath real data not found");
        }
        return ResponseEntity.ok(result);
    }
    
}
